package com.ruoyi.system.util;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.config.RuoYiConfig;

import javax.json.Json;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;


public class scriptTest {
    /** 获取 url ---> 对应的本地文件存储路径
     *  使用时最好先在本地测试，看路径是否正确
     */
    static String  getTrueFilePath(String url, String dataType) {
//        String basePath = RuoYiConfig.getUploadPath() + '/' + dataType;
        String basePath = "D:/ruoyi/uploadPath/upload" + '/' + dataType;
        String dateFilePath = url.substring(url.indexOf('/'+dataType) + dataType.length() + 1);
        String trueFilePath = basePath + dateFilePath;

        return trueFilePath;
    }

    public static String testCN_Lead(){
        // 测试中国主导 --B1B2
        String url1 ="http://localhost:8989/profile/upload/supplement/2024/08/30/ISO 7055 最初提案.txt";
        String url2 ="http://localhost:8989/profile/upload/supplement/2024/08/30/ISO 7055 最终文本.txt";

        String text1Path = getTrueFilePath(url1,"supplement");
        String text2Path = getTrueFilePath(url2,"supplement");

        String target = "B1";
        JSONObject paramsObject = new JSONObject();
        paramsObject.put("x",4);
        paramsObject.put("y",6);
        paramsObject.put("file1_path", text1Path);
        paramsObject.put("file2_path", text2Path);

        /** 解决 java 的json转到 python 会出现的双引号转义问题 */
        String params = paramsObject.toString().replace("\"", "\\\"");
        ISDataScoreUtil isDataScoreUtil = new ISDataScoreUtil();
        String res = isDataScoreUtil.cal_CN_Lead(target,params);
        return res;
    }

    public static String testCN_Join() throws UnsupportedEncodingException {
        // 测试中国参与 -- 投票记录、会议记录
        String url1 ="http://localhost:8989/profile/upload/supplement/2024/08/30/表1--ISO 9055 投票参与记录--A2B1.xlsx";
        String url2 ="http://localhost:8989/profile/upload/supplement/2024/08/30/表2--ISO 9055 会议参与记录--A3B2B3B4C.xlsx";

        String text1Path = getTrueFilePath(url1,"supplement");
        String text2Path = getTrueFilePath(url2,"supplement");

        String target = "B51";
        JSONObject paramsObject = new JSONObject();
        paramsObject.put("x",4);
        paramsObject.put("vote_record_path", text1Path);
        paramsObject.put("meeting_record_path", text2Path);

        /** 解决 java 的json转到 python 会出现的双引号转义问题 */
        String params = paramsObject.toString().replace("\"", "\\\"");
        ISDataScoreUtil isDataScoreUtil = new ISDataScoreUtil();
        String res = isDataScoreUtil.cal_CN_Join(target,params);
        return res;
    }

    public static void main(String[] args) {
        try{
            System.out.println("测试结果:"+testCN_Join());
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
